const demo = require(process.argv[2])
console.log('running', demo)

function main() {
    let parser = new demo.option_parser()
    console.log("parser:", parser)

    parser.add_string_option("product", "hisilicon/hispark_taurus_standard")
    parser.add_bool_option("n", true)
    parser.add_number_option("j", 4)
    console.log('result1:', parser.parse("--product hihope/rk3568 ohosm1 -n -j 8"))
    console.log('result2:', parser.parse("--product hihope/rk3569 ohosm2 -j 9"))

    try {
        console.log('result3:', parser.parse("--product"))
    } catch (e) {
        console.log('result3 e:', e)
    }

    try {
        console.log('result4:', parser.parse("-j abc"))
    } catch (e) {
        console.log('result4 e:', e)
    }

    console.log(1, parser.finalizer('get'))
    console.log(2, parser.finalizer('add', 123))
    console.log(3, parser.finalizer('get'))
    console.log(4, parser.finalizer('add', 456))
    console.log(5, parser.finalizer('add', 789))
    console.log(6, parser.finalizer('get'))

    console.log('is_option_parser1:', demo.is_option_parser(1))
    console.log('is_option_parser2:', demo.is_option_parser(demo.option_parser))
    console.log('is_option_parser3:', demo.is_option_parser(parser))
    console.log('is_option_parser4:', demo.is_option_parser(demo.is_option_parser))

    console.log("after main running")
}

main()
console.log("after main")

/*
running {
  option_parser: [Function: OptionParser],
  is_option_parser: [Function: is_option_parser]
}
that: OptionParser {}
D OptionParserData +41 Ctor
thiz: [Function: OptionParser]
parser: OptionParser {}
args: [ '--product', 'hihope/rk3568', 'ohosm1', '-n', '-j', '8' ]
, 'hihope/rk3568'
, '-n'
, '-j'
, '8'
result1: {
  product: 'hisilicon/hispark_taurus_standa',
  n: false,
  j: 8,
  args: [ 'ohosm1' ]
}
args: [ '--product', 'hihope/rk3569', 'ohosm2', '-j', '9' ]
, 'hihope/rk3569'
, '-j'
, '9'
result2: {
  product: 'hisilicon/hispark_taurus_standa',
  n: false,
  j: 9,
  args: [ 'ohosm2' ]
}
args: [ '--product' ]

result3 e: Error: product need argument
    at main (/home/luwh/repo/demos/third_party_demo/napi/src/16.object_wrap.js:15:40)
    at Object.<anonymous> (/home/luwh/repo/demos/third_party_demo/napi/src/16.object_wrap.js:41:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47
args: [ '-j', 'abc' ]
, 'abc'
result4 e: Error: parse -j type error, abc
    at main (/home/luwh/repo/demos/third_party_demo/napi/src/16.object_wrap.js:21:40)
    at Object.<anonymous> (/home/luwh/repo/demos/third_party_demo/napi/src/16.object_wrap.js:41:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47
1 []
2 undefined
3 [ 123 ]
4 undefined
5 undefined
6 [ 123, 456, 789 ]
is_option_parser1: false
is_option_parser2: false
is_option_parser3: true
is_option_parser4: false
after main running
after main
D ~OptionParserData +46 Dtor
D FinalizeFinalizerData +365 FinalizeFinalizerData
*/
